/*复用头部与尾部*/
define(["jquery"],function($){
	//ajax读取头部文件加载
	//法一
	//$("header").load("/html/include/header.html");
	//法二
	/*$.get("/html/include/header.html",function(data){
		//$("header").append(data);
		$("header").html(data);
	});*/
	//法三
	$.ajax({
		type: "get",
		url: "/html/include/header.html",
		success: function(data){
			$("header").html(data);
			//为搜索框绑定事件
			//$(".search>input:first").on("keyup",function(){});
			$(".search>input:first").keyup(function(){
				console.log(this);//this指的是绑定事件的DOM对象
				console.log($(this).val());
				var word = $(this).val(),
					url = `https://suggest.taobao.com/sug?code=utf-8&q=${word}&callback=?`;
				$.getJSON(url,function(data){
					console.log(data);
					var html = "";
					data.result.forEach(function(curr){
						html += `<div>${curr[0]}</div>`;
					});
					$(".suggest").html(html);
				});
			});
			//为suggest的孩子div绑定点击事件
			$(".suggest").delegate("div", "click", function(){
				console.log(this);
				$(".search>input:first").val($(this).text());
				$(".suggest").empty();
			});
		}
	});
	$("footer").load("/html/include/footer.html");
});





























